<?php

class Taxi_LoginController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }

    // LOGIN DE USUARI
    public function putAction()
    {
        
        
        $mail = $this->_getParam('id',NULL);
        $pass = $this->_getParam('pass',NULL);
        
        
        if(is_null($mail)){
            $res = -2;
        }
        else if (is_null($pass)) {
            $res = -3;
        }
        else{
            $model_taxi = new Taxi_Model_Taxistes();
            $res = $model_taxi->login($mail, $pass);
            
            if($res == 0){
                $model_estat = new Taxi_Model_Estat();
                $model_estat->login($mail);
                
                $model_authtaxi = new Taxi_Model_AuthTaxistes();
                $res = $model_authtaxi->insert_token($mail);
            }
             
        }
        
        echo Zend_Json_Encoder::encode($res);
        exit;
    }

    //PROVES
    public function getAction()
    {

        $mail = $this->_getParam('mail');
        $pass = $this->_getParam('pass');
        
        $model = new Taxi_Model_Taxistes();
        $res = $model->login($mail, $pass);
       
        
        echo Zend_Json_Encoder::encode($res);
        exit;
    }


}





